#pragma once

#define PPM_MAX_CHANNELS 8


typedef struct s_ppm_frame
{
	int				state;

	unsigned int	step_len;
	unsigned short	time_scale;
	short			value[PPM_MAX_CHANNELS];
	int				num_channels;
} t_ppm_frame;

typedef struct s_ppm_state
{
	t_ppm_frame		rx;
	t_ppm_frame		tx;

	int		min_smp;
	int		max_smp;

	short	thresh;
	short   peak;
	short	swing;

	short	last_smp;
	int		smp_txed;

} t_ppm_state;

void ppm_reset(t_ppm_state *p_state);
void ppm_set_tx(t_ppm_state *p_state, const unsigned short tenth_ms);

void ppm_process_sample(t_ppm_state *p_state, const short in);
short ppm_generate_sample(t_ppm_state *p_state);

bool ppm_has_framesync(t_ppm_state *p_state);
int ppm_get_value(t_ppm_state *p_state, const int channel);
int ppm_get_rx_channels(t_ppm_state *p_state);
void ppm_set_values(t_ppm_state *p_state, const short *values, const int count); // values are in range [0..128]
